﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSP.Common.Web;
using CSP.Model.CSP;
using CSP.Bll;
using CSP.Bll.IObjectBlls;
using CSP.Web.Master;
using CSP.Web.UserControls;

namespace CSP.Web.MyHome.Address
{
    public partial class Detail : CSPMyHome
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ((HomeMaster)Master).SelectedNavigationLink = MyHomeLeftNavigationLink.Address;
            if (Request["id"] != null)
            {
                BindAddressUI();
            }
            
        }

        private void BindAddressUI()
        {
            CSP.Model.CSP.Address address = GetModifyAddress();

            L_Name.Text = address.Name;
            L_Introduction.Text = address.Introduction;
            L_Province.Text = address.CN_Province;
            L_City.Text = address.CN_City;
            L_County.Text = address.CN_County;
            L_Street.Text = address.Street;

            L_Mobile.Text = address.Mobile;
            L_Phone.Text = address.Telephone;
            L_Email.Text = address.Email;

            foreach (Map map in address.Maps)
            {
                Txt_CenterPointX.Value = map.CenterPointX;
                Txt_CenterPointY.Value = map.CenterPointY;
                Txt_MarkerPointX.Value = map.MarkerPointX;
                Txt_MarkerPointY.Value = map.MarkerPointY;
                Txt_Zoom.Value = map.Zoom.ToString();
            }
        }

        /// <summary>
        /// 获取将要修改的Address 数据
        /// </summary>
        private CSP.Model.CSP.Address GetModifyAddress()
        {
            CSP.Model.CSP.Address address = null;
            CSPBllFactory factory = CSPBllFactory.GetInstance();
            using (IAddressBll addressBll = factory.GetAddressBll())
            {
                address = addressBll.GetByIdAndUser(Convert.ToInt32(Request["id"]), UserProvider.UserName);
            }
            return address;
        }
    }
}